import React from 'react';

import { Route, Switch, Link} from 'react-router-dom';

import Bundle from './Bundle';

import Loading from 'COMPONENTS/Loading/Loading';
import Home from 'bundle-loader?lazy&name=home!PAGES/Home/Home';
import Page1 from 'bundle-loader?lazy&name=page1!PAGES/Page1/Page1';
import Counter from 'bundle-loader?lazy&name=counter!PAGES/Counter/Counter';
import UserInfo from 'bundle-loader?lazy&name=userInfo!PAGES/UserInfo/UserInfo';
import NotFound from 'bundle-loader?lazy&name=NotFound!PAGES/NotFound/NotFound';


const createComponent = (component) => (props) => (
    <Bundle load={component}>
        {
            (Component) => Component ? <Component {...props} /> : <Loading/>
        }
    </Bundle>
);
const getRouter = () => (
        <div>

            <Switch>
                <Route exact path="/" component={createComponent(Home)}/>
                <Route path="/page1" component={createComponent(Page1)}/>
                <Route path="/counter" component={createComponent(Counter)}/>
                <Route path="/userinfo" component={createComponent(UserInfo)}/>
                <Route component={createComponent(NotFound)}/>
            </Switch>
        </div>
);

export default getRouter;